package com.huang.core.util

import android.content.Context
import androidx.annotation.DrawableRes
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions

object ImageLoad {

    fun glide(context: Context, url: String? = "", imageView: ImageView, @DrawableRes placeHolder: Int = 0, @DrawableRes errorImg: Int = 0) {
        val glideOption = Glide.with(context).load(url).dontAnimate()
        val requestOptions = RequestOptions().placeholder(placeHolder).error(errorImg)
        glideOption.apply(requestOptions).into(imageView)
    }

    fun glide(context: Context, @DrawableRes url: Int?, imageView: ImageView, @DrawableRes placeHolder: Int = 0, @DrawableRes errorImg: Int = 0) {
        val glideOption = Glide.with(context).load(url).dontAnimate()
        val requestOptions = RequestOptions().placeholder(placeHolder).error(errorImg)
        glideOption.apply(requestOptions).into(imageView)
    }

    fun glide(context: Context, url: String? = "", imageView: ImageView, requestOptions: RequestOptions? = null) {
        val glideOption = Glide.with(context).load(url).dontAnimate()
        if (requestOptions != null) glideOption.apply(requestOptions)
        glideOption.into(imageView)
    }

    fun glide(context: Context, @DrawableRes url: Int?, imageView: ImageView, requestOptions: RequestOptions? = null) {
        val glideOption = Glide.with(context).load(url).dontAnimate()
        if (requestOptions != null) glideOption.apply(requestOptions)
        glideOption.into(imageView)
    }

    fun glideCircle(context: Context, url: String?, imageView: ImageView, @DrawableRes placeHolder: Int = 0, @DrawableRes errorImg: Int = 0) {
        val glideOption = Glide.with(context).load(url).dontAnimate()
        val requestOptions = RequestOptions.circleCropTransform().placeholder(placeHolder).error(errorImg)
        glideOption.apply(requestOptions).into(imageView)
    }

    fun glideCircle(context: Context, url: Int?, imageView: ImageView, @DrawableRes placeHolder: Int = 0, @DrawableRes errorImg: Int = 0) {
        val glideOption = Glide.with(context).load(url).dontAnimate()
        val requestOptions = RequestOptions.circleCropTransform().placeholder(placeHolder).error(errorImg)
        glideOption.apply(requestOptions).into(imageView)
    }

}